//
//  GuidePageView.m
//  Btpin
//
//  Created by Vic on 2019/4/13.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "GuidePageView.h"

@interface GuidePageView () <UIScrollViewDelegate>
{
    UIScrollView *scrollView;
    UIPageControl *pageCtl;
    UIButton *removeButton;
    UIButton *skipButton;
}
@end

@implementation GuidePageView

- (instancetype)init {
    self = [super init];
    if (self) {
        [self initUI];
    }
    return self;
}
- (void)initUI {
    self.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
    
    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    scrollView.pagingEnabled = YES;
    scrollView.delegate = self;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.contentSize = CGSizeMake(WIDTH*2, 0);
    scrollView.bounces = NO;
    [self addSubview:scrollView];
    
    UIImageView *leftImageView = [UIToolsControl initImageViewWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) imageName:@"guide_n_1"];
    leftImageView.backgroundColor = [UIColor redColor];
    leftImageView.contentMode = UIViewContentModeScaleAspectFill;
    leftImageView.layer.masksToBounds = YES;
    [scrollView addSubview:leftImageView];
    
    UIImageView *middleImageView = [UIToolsControl initImageViewWithFrame:CGRectMake(WIDTH, 0, WIDTH, HEIGHT) imageName:@"guide_n_2"];
    middleImageView.contentMode = UIViewContentModeScaleAspectFill;
    middleImageView.layer.masksToBounds = YES;
    [scrollView addSubview:middleImageView];
    
    if (SIMEmojKeyBoardisFullProfiledScreen) {
        leftImageView.image = [UIImage imageNamed:@"guide_n_b_1"];
        middleImageView.image = [UIImage imageNamed:@"guide_n_b_2"];
    }
    
    /*
    if (isiPhoneXsMax) {
        leftImageView.image = [UIImage imageNamed:@"guide_xsmax_1"];
        middleImageView.image = [UIImage imageNamed:@"guide_xsmax_2"];
    } else if (isiPhoneXr) {
        leftImageView.image = [UIImage imageNamed:@"guide_xr_1"];
        middleImageView.image = [UIImage imageNamed:@"guide_xr_2"];
    } else if (isiPhoneX) {
        leftImageView.image = [UIImage imageNamed:@"guide_x_1"];
        middleImageView.image = [UIImage imageNamed:@"guide_x_2"];
//        rightImageView.image = [UIImage imageNamed:@"guide_x_3"];
    } else if (isiPhonePlus) {
        leftImageView.image = [UIImage imageNamed:@"guide_plus_1"];
        middleImageView.image = [UIImage imageNamed:@"guide_plus_2"];
//        rightImageView.image = [UIImage imageNamed:@"guide_plus_3"];
    } else if (isiPhone6) {
        leftImageView.image = [UIImage imageNamed:@"guide_6_1"];
        middleImageView.image = [UIImage imageNamed:@"guide_6_2"];
//        rightImageView.image = [UIImage imageNamed:@"guide_6_3"];
    } else {
        leftImageView.image = [UIImage imageNamed:@"guide_5_1"];
        middleImageView.image = [UIImage imageNamed:@"guide_5_2"];
//        rightImageView.image = [UIImage imageNamed:@"guide_5_3"];
    }
    */
    
    CGFloat h = 0;
    if (!SIMEmojKeyBoardisFullProfiledScreen) {
        h = 120;
    } else {
        h = 160;
    }

//    skipButton = [UIToolsControl initButtonWithFrame:CGRectMake(WIDTH-80, HeightOfTabBarSafeMargin+30, 60, 30) imageName:nil target:self action:@selector(removeButtonTap) title:@"跳过" titleColor:THEMECOLOR_OF_TEXT_GRAY];
//    skipButton.titleLabel.font = Font(Font_SIZE_17);
//    skipButton.layer.cornerRadius = 15;
//    skipButton.layer.masksToBounds = YES;
//    skipButton.layer.borderColor = THEMECOLOR_OF_TEXT_GRAY.CGColor;
//    skipButton.layer.borderWidth = 1;
//    [self addSubview:skipButton];
    //    [self.layer addSublayer:skipButton.layer];
    
//    removeButton = [UIToolsControl initButtonWithFrame:CGRectMake(WIDTH/2-60, HEIGHT-HeightOfTabBarSafeMargin-h, 120, 44) imageName:nil target:self action:@selector(removeButtonTap) title:@"进入比特聘" titleColor:COLOR_OF_WHITE];
//    removeButton.titleLabel.font = Font(Font_20);
//    removeButton.layer.cornerRadius = 5;
//    removeButton.layer.masksToBounds = YES;
//    removeButton.backgroundColor = THEMECOLOR_OF_ORANGE;
    removeButton = [UIToolsControl initButtonWithFrame:CGRectMake(WIDTH/2-80, HEIGHT-SIMEmojKeyBoardkBottomNOSafeArea_Height-h, 160, 66) imageName:nil target:self action:@selector(removeButtonTap) title:nil titleColor:nil];
    removeButton.hidden = YES;
    [self addSubview:removeButton];
    
//    pageCtl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, StartY(removeButton)-30, WIDTH, 20)];
//    pageCtl.numberOfPages = 2;
//    pageCtl.pageIndicatorTintColor = THEMECOLOR_OF_GRAY;
//    pageCtl.currentPageIndicatorTintColor = THEMECOLOR_OF_ORANGE;
//    [self addSubview:pageCtl];
}
- (void)removeButtonTap {
    if (self.delegate && [self.delegate respondsToSelector:@selector(guidePageCallback)]) {
        [self.delegate guidePageCallback];
    }
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.x < 1) {
        removeButton.hidden = YES;
        skipButton.hidden = NO;
//        pageCtl.currentPage = 0;
    } else if (scrollView.contentOffset.x == WIDTH) {
//        removeButton.hidden = YES;
//        skipButton.hidden = NO;
//        pageCtl.currentPage = 1;
        removeButton.hidden = NO;
        skipButton.hidden = YES;
//        pageCtl.currentPage = 1;
    }
}

@end
